<html>
	<head>
		<title>Carnegie FS | Employee Area</title>
		#{include 'html_head.html'/}
		<script type="text/javascript">
			$(document).ready(function() {
				$("#reset_password_dialog").dialog({
					width: 400,
					height: 150,
					modal: true,
					autoOpen: false
				});
				
				$("#deposit_dialog").dialog({
					width: 400,
					height: 200,
					modal: true,
					autoOpen: false
				});	
			});
			var open_reset_password_dialog = function(){
				$("#reset_password_dialog").dialog('open');
			};				
			var open_deposit_dialog = function(){
				$("#deposit_dialog").dialog('open');
			};
		</script>
	</head>

	<body>
		<div id="container">
			<!-- Page Header -->
			#{include 'header.html'/}
	
			<!-- Content Area -->
			<div id="content">
				<a href="/employee/"><< Back to main</a>
				<div class="title">Staff Admin</div>
				<table width="100%">
					<tr>
						<td class="profile_item_lbl">Employee Name</td>
						<td class="profile_item_value">${employee.firstname} ${employee.lastname}</td>
					</tr>
					<tr>
						<td class="profile_item_lbl">Username</td>
						<td class="profile_item_value">${employee.username}</td>
					</tr>			
					<tr>
						<td class="profile_item_lbl">Customer Services</td>
						<td>
							<button class="button_green" onclick="open_reset_password_dialog()">Reset Password</button>
							<button class="button_green" onclick="open_deposit_dialog()">Deposit Check</button>
						</td>
					</tr>				
				</table>
				
				<br /><hr /><br />
				
				<div class="title">Customer Details</div>
				<table width="100%">
					<tr>
						<td class="profile_item_lbl alt_tbl_header">Account Holder</td>
						<td class="profile_item_value">${customer.firstname} ${customer.lastname}</td>
					</tr>
					<tr>
						<td class="profile_item_lbl alt_tbl_header">Available Balance</td>
						<td class="profile_item_value">USD ${availableBalance}</td>
					</tr>
					<tr>
						<td class="profile_item_lbl alt_tbl_header">Ledger Balance</td>
						<td class="profile_item_value">USD ${customer.cash}</td>
					</tr>
				</table>
				
				<div class="clear"></div>
				
				<div class="title">Portfolio</div>
				
				<table>
					<tr>
						<th class="tbl_header alt_tbl_header">Fund</th>
						<th class="tbl_header alt_tbl_header">Shares</th>
						<th></th>
						<th></th>
					</tr>
					
					#{list items:positions, as:'pos'}
					<tr>
						<td class="tbl_row alt_tbl_row">${pos.fund.symbol}</td>
						<td class="tbl_row alt_tbl_row right_aligned">${pos.shares.setScale(3)}</td>
					</tr>
					#{/list}
				</table>			

				<div class="clear"></div>
				
				<div class="title">Transaction History</div>
				
				%{ int count = 0; }%
				
				<table>
					<tr>
						<th class="tbl_header alt_tbl_header">Date</th>
						<th class="tbl_header alt_tbl_header">Operation</th>
						<th class="tbl_header alt_tbl_header">Fund</th>
						<th class="tbl_header alt_tbl_header">No of Shares</th>
						<th class="tbl_header alt_tbl_header">Price</th>
						<th class="tbl_header alt_tbl_header">Amount</th>
					</tr>
					
					#{list items:pending, as:'pending_item'}
					<tr>
						<td class="tbl_row alt_tbl_row"><i><font color="#777">Pending...</font></i></td>
						<td class="tbl_row alt_tbl_row"><i><font color="#777">${pending_item.transaction_type}</font></i></td>
						<td class="tbl_row alt_tbl_row"><i><font color="#777">%{if(pending_item.transaction_type.equalsIgnoreCase("buy") || pending_item.transaction_type.equalsIgnoreCase("sell")){}% ${pending_item.position.fund.symbol} %{}}%</font></i></td>
						<td class="tbl_row alt_tbl_row right_aligned"><i><font color="#777">%{if(pending_item.shares!=null){if(pending_item.transaction_type.equalsIgnoreCase("buy") || pending_item.transaction_type.equalsIgnoreCase("sell")){}% ${pending_item.shares.setScale(3)}%{}}%%{if(pending_item.transaction_type.equalsIgnoreCase("buy")){}%*%{}}}%</font></i></td>
						<td class="tbl_row alt_tbl_row right_aligned"><i><font color="#777">%{if(prices.get(count)!=null && (pending_item.transaction_type.equalsIgnoreCase("buy") || pending_item.transaction_type.equalsIgnoreCase("sell"))){}% ${prices.get(count).setScale(2)}* %{}}%</font></i></td>
						<td class="tbl_row alt_tbl_row right_aligned"><i><font color="#777">USD ${pending_item.amount}%{if(pending_item.transaction_type.equalsIgnoreCase("sell")){}%*%{}}%</font></i></td>
					</tr>
					%{ count++; }%
					#{/list}
					
					#{list items:executed, as:'executed_item'}
					<tr>
						<td class="tbl_row alt_tbl_row">${executed_item.execute_date.format()}</td>
						<td class="tbl_row alt_tbl_row">${executed_item.transaction_type}</td>
						<td class="tbl_row alt_tbl_row">#{if executed_item.transaction_type = 'buy' || executed_item.transaction_type == 'sell'}${executed_item.position.fund.symbol}#{/if}</td>
						<td class="tbl_row alt_tbl_row right_aligned">%{if(executed_item.shares!=null){}% ${executed_item.shares.setScale(3)} %{}}%</td>
						<td class="tbl_row alt_tbl_row right_aligned">%{if(executed_item.shares!=null && executed_item.amount!=null){}% ${(executed_item.amount/executed_item.shares).format('#,##0.00')} %{}}%</td>
						<td class="tbl_row alt_tbl_row right_aligned">USD ${executed_item.amount}</td>
					</tr>
					#{/list}
				</table>
				Values marked with asterisk (*) indicate tentative amount; actual value transacted may differ.
			</div>
			
			<!-- Page Footer -->
			#{include 'footer.html'/}
			
			<div id="reset_password_dialog" title="Reset Password">
				#{form @EmployeeArea.resetCustomerPasswordHandler()}
					<table width="100%">
						<tr>
							<td class="tbl_header">Customer's Username</td>
							<td class="tbl_row"><input type="text" name="username" value="${customer.username}" readonly="readonly" class="border_zero" /></td>
						</tr>
					</table>
					<div align="right"><button class="button_black">Reset Password</button></div>
				#{/form}
			</div>		
			
			<div id="deposit_dialog" title="Deposit Check">
				#{form @EmployeeArea.depositCheck()}
					<table width="100%">
						<tr>
							<td class="tbl_header">Customer's Username</td>
							<td class="tbl_row"><input type="text" name="username" value="${customer.username}" readonly="readonly" class="border_zero" /></td>
						</tr>				
						<tr>
							<td class="tbl_header">Amount</td>
							<td class="tbl_row"><input type="text" name="depositamount" placeholder="in USD" /></td>
						</tr>
					</table>
					<div align="right"><button class="button_black">Deposit Check</button></div>
				#{/form}
			</div>	
		</div>
	</body>

</html>